<template>
  <div>
    <el-row :gutter="10" style="margin: 20px auto">
      <el-col :span="6">
       <el-card style="background-image: linear-gradient(160deg, #b100ff 20%,#00b3ff 80%);">
         <div style="color: #ffffff;"><icon class="el-icon-user-solid"></icon>用户总数</div>
         <div style="padding: 15px 0;text-align: center;font-weight: bold;font-size: 30px;color: white">{{ userTotal }}</div>
       </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="background-image: linear-gradient(160deg, #00ffd5 20%,#008cff 80%);">
          <div style="color: #fff;"><icon class="el-icon-s-help"></icon>单词总数</div>
         <div style=" display: flex;justify-content: space-between;align-items: center;margin-top: 10px">
           <div style="padding: 10px 10px;font-weight: bold;font-size: 30px;color: white;margin-right: 5px">{{ wordtTotal }}</div>
           <div>名词<el-tag style="margin: 5px 5px">{{n}}</el-tag></div>
           <div>动词<el-tag type="success" style="margin: 5px 0">{{v}}</el-tag></div>
           <div>形容词<el-tag type="info" style="margin: 5px 2px">{{adj}}</el-tag></div>
           <div>副词<el-tag type="warning" style="margin: 5px 2px">{{adv}}</el-tag></div>
           <div>介词<el-tag type="danger" style="margin: 5px 0">{{j}}</el-tag></div>
         </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="background-image: linear-gradient(160deg, #ffce00 20%,#ff8b00 80%);">
          <div style="color: #ffffff;"><icon class="el-icon-folder-opened"></icon>文件总数</div>
          <div style=" display: flex;justify-content: space-between;align-items: center;margin-top: 10px">
            <div style="padding: 10px 10px;font-weight: bold;font-size: 30px;color: white;margin-right: 5px">{{ fileTotal }}</div>
            <div>jpg<el-tag style="margin: 5px 0">{{jpg}}</el-tag></div>
            <div>png<el-tag type="success" style="margin: 5px 0;">{{png}}</el-tag></div>
            <div>pdf<el-tag type="info" style="margin: 5px 0;">{{pdf}}</el-tag></div>
            <div>ppt<el-tag type="warning" style="margin: 5px 0;">{{ppt}}</el-tag></div>
            <div>doc<el-tag type="danger" style="margin: 5px 0;">{{doc}}</el-tag></div>
            <div>xsl<el-tag type="danger" style="margin: 5px 0;">{{xsl}}</el-tag></div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="background-image: linear-gradient(160deg, #ff0064 20%,#ca00ff 80%);">
          <div style="color: #fffbfb;"><icon class="el-icon-s-opportunity"></icon>收藏总数</div>
          <div style="padding: 15px 0;text-align: center;font-weight: bold;font-size: 30px;color: white">{{ userTotal }}</div>
        </el-card>
      </el-col>
    </el-row>

    <el-row style="margin-top: 55px; display: flex;justify-content: space-between;align-items: center;">
        <div id="main" style="width: 800px; height: 640px;"></div>
        <div id="pie" style="width: 800px; height: 640px;"></div>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: "backHome",
  data(){
    return{
      userTotal:"",
      wordTotal:"",
      n:"",
      v:"",
      adj:"",
      adv:"",
      j:"",
      data1:[],
      fileTotal:"",
      png:"",
      jpg:"",
      pdf:"",
      ppt:"",
      doc:"",
      xsl:"",
    }
  },
  mounted() {

    const chartDom = document.getElementById('main');
    const myChart = echarts.init(chartDom);
    const option = {
      title: {
        text: '各季度用户、单词数量统计',
        subtext: '趋势图',
        left: 'center'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: ["第一季度", "第二季度", "第三季度", "第四季度"]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: "用户",
          data: [],
          type: 'bar'
        },
        {
          name: "用户",
          data: [],
          type: 'line'
        },
        {
          name: "单词",
          data: [],
          type: 'bar'
        },
        {
          name: "单词",
          data: [],
          type: 'line'
        },
        {
          name: "文件",
          data: [],
          type: 'bar'
        },
        {
          name: "文件",
          data: [],
          type: 'line'
        }
      ]
    };

    this.request.get("/echarts/members").then(res => {
      // 填空
      // option.xAxis.data = res.data.x
      option.series[0].data= [res.data[0],res.data[1],res.data[2],res.data[3]]
      option.series[1].data =[res.data[0],res.data[1],res.data[2],res.data[3]]
      option.series[2].data =[res.data[11],res.data[12],res.data[13],res.data[14]]
      option.series[3].data =[res.data[11],res.data[12],res.data[13],res.data[14]]
      option.series[4].data =[res.data[15],res.data[16],res.data[17],res.data[18]]
      option.series[5].data =[res.data[15],res.data[16],res.data[17],res.data[18]]
      this.userTotal=res.data[4]
      this.n=res.data[5]
      this.v=res.data[6]
      this.adj=res.data[7]
      this.adv=res.data[8]
      this.j=res.data[9]
      this.wordtTotal=res.data[10]
      this.fileTotal=res.data[19]
      this.jpg=res.data[20]
      this.png=res.data[21]
      this.pdf=res.data[22]
      this.ppt=res.data[23]
      this.doc=res.data[24]
      this.xsl=res.data[25]
      // 数据准备完毕之后再set
      myChart.setOption(option);
    })

  // 饼图
    const pieOption = {
      title: {
        text: '单词词性、文件类型数量统计',
        subtext: '比例图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: ["名词", "动词", "形容词", "副词", "介词", "jpg", "png", "pdf", "ppt", "doc", "xsl"]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          type: 'pie',
          radius: '62%',
          center: ['30%', '55%'],
          label: {            //饼图图形上的文本标签
            normal: {
              show: true,
              position: 'inner', //标签的位置
              textStyle: {
                fontWeight: 300,
                fontSize: 14,    //文字的字体大小
                color: "#fff"
              },
              formatter: '{d}%'
            }
          },
          data: [],  // 填空
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        },
        {
          type: 'pie',
          radius: '50%',
          center: ['79%', '38%'],
          label: {            //饼图图形上的文本标签
            normal: {
              show: true,
              position: 'inner', //标签的位置
              textStyle: {
                fontWeight: 300,
                fontSize: 14,    //文字的字体大小
                color: "#fff"
              },
              formatter: '{d}%'
            }
          },
          data: [],  // 填空
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    const pieDom = document.getElementById('pie');
    const pieChart = echarts.init(pieDom);

    this.request.get("/echarts/members").then(res => {

      pieOption.series[0].data = [
        {name: "名词", value: res.data[5]},
        {name: "动词", value: res.data[6]},
        {name: "形容词", value: res.data[7]},
        {name: "副词", value: res.data[8]},
        {name: "介词", value: res.data[9]},
      ]
      pieOption.series[1].data = [
        {name: "jpg", value: res.data[20]},
        {name: "png", value: res.data[21]},
        {name: "pdf", value: res.data[22]},
        {name: "ppt", value: res.data[23]},
        {name: "doc", value: res.data[24]},
        {name: "xsl", value: res.data[25]},
      ]
      pieChart.setOption(pieOption)
    })
  },
  created() {
    setRoutes()
  },
  }

</script>

<style scoped>

</style>